﻿//Write a program that downloads a file from Internet (e.g. http://www.devbg.org/img/Logo-BASD.jpg)
//and stores it the current directory. Find in Google how to download files in C#.
//Be sure to catch all exceptions and to free any used resources in the finally block.

using System;
using System.Net;
using System.Threading;
using System.Diagnostics;
using System.Security;


class DownloadFile
{
    static void Main()
    {
        using (WebClient wbc = new WebClient())
        {
            try
            {
                Console.Write("Enter URL Path to download file: ");
                string path = Console.ReadLine();
                Console.Write("Enter Filename : ");
                string filename = Console.ReadLine();

                wbc.DownloadFileAsync(new Uri(path), filename);
                string answer = Console.ReadLine();
                Console.WriteLine("Download Finished!");
            }
            catch (WebException)
            {
                Console.WriteLine("Entered address is invalid.");
            }
            catch (ArgumentNullException)
            {
                Console.WriteLine("Given address cannot be null.");
            }
            catch (ArgumentException)
            {
                Console.WriteLine("Given address is not valid.");
            }
            catch (NotSupportedException)
            {
                Console.WriteLine("This method does not support simultaneous downloads.");
            }
            catch (SecurityException)
            {
                Console.WriteLine("You don`t have a permission to download this file.");
            }
            finally
            {
                wbc.Dispose();
            }
        }
    }
}
    
 



